<?php


namespace Tbf\Component\Http\ServeFile;


use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;

class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface{
    protected $defaultMimeType = array(
        'css'=>'text/css',
        'js'=>'application/javascript',
        'jpg'=>'image/jpeg',
        'gif'=>'image/gif',
        'png'=>'image/png',
    );

    /**
     * Guesses the mime type of the file with the given path.
     *
     * @param string $path The path to the file
     *
     * @return string         The mime type or NULL, if none could be guessed
     *
     * @throws FileNotFoundException  If the file does not exist
     * @throws AccessDeniedException  If the file could not be read
     */
    public function guess($path)
    {
        $extension = pathinfo($path,PATHINFO_EXTENSION);
        if (empty($extension)){
            return null;
        }
        if (!empty($this->defaultMimeType[$extension])){
            return $this->defaultMimeType[$extension];
        }
        return null;
    }

}